﻿/*****************************************************************************
 
 Use of Ext is under the Ext JS license, for more information, 
 please visit http://extjs.com/products/license.php page. 
  
 You should confirm that you have read, understood and accept ethical criteria listed. 
 If not, see <http://www.mvcnext.com/license/>.
  
 Version: 1.0.0.0
 Website: http://www.mvcnext.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Web.UI;
using System.Text;

namespace MVCnExt.Web.UI.Ext
{    
    [ParseChildren(true)]      
    public class ExtWindow : ExtPanel, INamingContainer
    {
        private List<ExtComponent> _items = new List<ExtComponent>();
        private List<ScriptReference> _references = new List<ScriptReference>();

        public override List<ScriptReference> GetScriptReferences()
        {
            _references.AddRange(base.GetScriptReferences());

            return _references;
        }

        public override IList<ScriptDescriptor> GetScriptDescriptors()
        {           

            IList<ScriptDescriptor> list = base.GetScriptDescriptors();

            ScriptControlDescriptorBase desc = (ScriptControlDescriptorBase)list[0];

            desc.Type = "Ext.Window";

            String[] properties = new String[]{
               "modal", "title", "autoHeight", "autoWidth", "height", "pageX", 
                "pageY", "width", "x", "y", "minSize", "maxSize", "layout"     
            };

            Type component = typeof(ExtWindow);

            foreach (String property in properties)
            {
                PropertyInfo i = component.GetProperty(property);
                
                if (i == null)
                    throw new InvalidOperationException(String.Format("Property not found, 'ExtWindow.{0}'", property));

                Object value = i.GetValue(this, null);

                if (value == null)
                {
                    continue;
                }

                if (!(value is String))
                    desc.AddPropertyBase(property, value);
                else
                    desc.AddPropertyBase(property, String.Format("'{0}'", value));
            }          

            return list;
        }

        ///// <summary>
        ///// Instantiate the Body template so we can add child controls
        ///// </summary>
        //protected override void CreateChildControls()
        //{
        //    //call base method
        //    base.CreateChildControls();
                      
        //}        

        #region Public Properties

        /// <summary>
        /// Specify the alignment of labels of the form elements.
        /// </summary>
        public String labelAlign { get; set; }       

       
        /// <summary>
        /// Specify the width of each label.
        /// </summary>
        public String labelWidth { get; set; }
    
        /// <summary>
        /// True to make the window modal and mask everything behind it when displayed, 
        /// false to display it without restricting access to other UI elements (defaults to false).
        /// </summary>
        public Boolean? modal { get; set; }

        public override Unit? height { get; set; }

        public override Unit? width { get; set; }       

        #endregion
    }
}
